package com.ebanma.cloud.user.dubbo;

import javax.annotation.Resource;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.ebanma.cloud.user.api.model.User;
import com.ebanma.cloud.user.api.service.UserDubboService;
import com.ebanma.cloud.user.service.IUserService;
import com.ebanma.cloud.utils.JwtUtil;
import com.ebanma.cloud.utils.RedisUtil;
import org.apache.dubbo.config.annotation.DubboService;

/**
 * @author wangxin
 * @version $ Id: UserDubboServiceImpl, v 0.1 2023/02/17 16:12 banma-0369 Exp $
 */
@DubboService
public class UserDubboServiceImpl implements UserDubboService {
    @Resource
    private IUserService userService;
    @Resource
    private JwtUtil jwtUtil;

    @Resource
    private RedisUtil redisUtil;

    @Override
    public User getUser(String token) {
        String uuid = null;
        User user = null;
        if (StringUtils.isNotBlank(uuid = jwtUtil.verifierJwtToken(token))) {
            String userJson = redisUtil.get(uuid);
            //存入用户信息，方便方法进行调取
            user = JSONUtil.toBean(userJson, User.class);
        }
        return user;
    }
}
